/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007-2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.security.bean.impl;

import org.springframework.security.GrantedAuthority;

import com.genia.toolbox.basics.i18n.I18nMessage;
import com.genia.toolbox.security.bean.GrantedAuthorityComparator;
import com.genia.toolbox.security.bean.MutablePermission;
import com.genia.toolbox.security.bean.Permission;

/**
 * implementation of {@link MutablePermission}.
 */
public class PermissionImpl
    implements MutablePermission
{

  /**
   * the generated serial version uid.
   */
  private static final long serialVersionUID = 1583927026756813920L;

  /**
   * the description of the permission.
   */
  private I18nMessage description;

  /**
   * the name of the permission.
   */
  private I18nMessage name;

  /**
   * the category of the permission.
   */
  private I18nMessage category;

  /**
   * the reference name of the permission.
   */
  private String authority;

  /**
   * whether this permission is displayable or only used by the system.
   */
  private boolean displayable = true;



  /**
   * getter for the description property.
   * 
   * @return the description
   */
  public I18nMessage getDescription()
  {
    return description;
  }



  /**
   * setter for the description property.
   * 
   * @param description
   *          the description to set
   */
  public void setDescription(I18nMessage description)
  {
    this.description = description;
  }



  /**
   * getter for the name property.
   * 
   * @return the name
   */
  public I18nMessage getName()
  {
    return name;
  }



  /**
   * setter for the name property.
   * 
   * @param name
   *          the name to set
   */
  public void setName(I18nMessage name)
  {
    this.name = name;
  }



  /**
   * getter for the authority property.
   * 
   * @return the authority
   */
  public String getAuthority()
  {
    return authority;
  }



  /**
   * setter for the authority property.
   * 
   * @param authority
   *          the authority to set
   */
  public void setAuthority(String authority)
  {
    this.authority = authority;
  }



  /**
   * getter for the category property.
   * 
   * @return the category
   */
  public I18nMessage getCategory()
  {
    return category;
  }



  /**
   * setter for the category property.
   * 
   * @param category
   *          the category to set
   */
  public void setCategory(I18nMessage category)
  {
    this.category = category;
  }



  /**
   * getter for the displayable property.
   * 
   * @return the displayable
   */
  public boolean isDisplayable()
  {
    return displayable;
  }



  /**
   * setter for the displayable property.
   * 
   * @param displayable
   *          the displayable to set
   */
  public void setDisplayable(boolean displayable)
  {
    this.displayable = displayable;
  }



  /**
   * Compares this object with the specified object for order. Returns a
   * negative integer, zero, or a positive integer as this object is less than,
   * equal to, or greater than the specified object.
   * <p>
   * 
   * @param permission
   *          the {@link Permission} to compare with
   * @return a negative integer, zero, or a positive integer as this object is
   *         less than, equal to, or greater than the specified object
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  public int compareTo(Object permission)
  {
    return GrantedAuthorityComparator.INSTANCE.compare(this, (GrantedAuthority) permission);
  }

}
